package cn.iocoder.yudao.module.system.controller.app.noticeread;

import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.system.controller.app.noticeread.vo.AppNoticeReadRespVO;
import cn.iocoder.yudao.module.system.service.noticeread.NoticeReadService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;

@Tag(name = "用户 APP - 用户通知公告阅读记录")
@RestController
@RequestMapping("/system/notice-read")
@Validated
public class AppNoticeReadController {

    @Resource
    private NoticeReadService noticeReadService;

    @GetMapping("/get")
    @Operation(summary = "获得用户通知公告阅读记录")
    public CommonResult<AppNoticeReadRespVO> getNoticeRead() {
        final Long userId = getLoginUserId();
        final Integer unReadNoticeCount = noticeReadService.selectUnreadNoticeCountByUserId(userId, CommonStatusEnum.ENABLE);
        final AppNoticeReadRespVO res = new AppNoticeReadRespVO();
        res.setUnReadNoticeCount(unReadNoticeCount);
        return success(res);
    }


}